﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class QUANHEDAO:IData<QUANHE> 
 	{
		public QUANHEDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref QUANHE item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + QUANHE.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_QUANHE", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + QUANHE.c_MAQH, item.MAQH), new SqlParameter("@" + QUANHE.c_LOAIQH, item.LOAIQH));
			if(t == 0)
				item.ID = Convert.ToInt32(obj);
			return i;
		}

		public override QUANHE GetItem(IDataReader dr)
		{
			QUANHE obj = new QUANHE();
			obj.ID = Convert.ToInt32(dr[QUANHE.c_ID]);
			obj.MAQH = Convert.ToString(dr[QUANHE.c_MAQH]);
			obj.LOAIQH = Convert.ToString(dr[QUANHE.c_LOAIQH]);
			return obj;
		}

		public override List<QUANHE> GetAll()
		{
			return GetAll("sp_GetAllQUANHE", CommandType.StoredProcedure);
		}

		public override QUANHE GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt32(id));
		}
		public override QUANHE GetItemById(QUANHE item){
			throw new NotImplementedException();
		}

	}

 }
